#ifndef STATEMENT_HEADER_C__
#define STATEMENT_HEADER_C__

#include <stdlib.h>
#include "basic.h"
#include "declaration.h"
#include "expression.h"
#include "type.h"

#if 0
import std.lib;
import basic;
import declaration;
import expression;
import type;
#endif

struct Statement;
struct StatementList;
void freeStatement(struct Statement*);
void freeStatementList(struct StatementList*);

enum StatementTag
{
	ASSIGNMENT_STATEMENT,
	BLOCK_STATEMENT,
	EMPTY_STATEMENT,
	ENUM_DECLARATION_STATEMENT,
	EXPRESSION_STATEMENT,
	FLOW_STATEMENT,
	FUNCTION_DECLARATION_STATEMENT,
	IF_STATEMENT,
	LABEL_STATEMENT,
	POSTFIX_STATEMENT,
	RETURN_STATEMENT,
	STRUCT_DECLARATION_STATEMENT,
	UNION_DECLARATION_STATEMENT,
	VARIABLE_DECLARATION_STATEMENT,
	WHILE_STATEMENT
};

struct Statement
{
	enum StatementTag tag;
	void* statement;
};

// The implementations of these functions are in statement.c
struct Statement* allocateStatement(enum StatementTag tag, void* statement);
void freeStatement(struct Statement* s);

struct StatementList
{
	struct Statement* head;
	struct StatementList* tail;
};

struct StatementList* allocateStatementList(
	struct Statement* head,
	struct StatementList* tail)
{
	assert(head != NULL);

	struct StatementList* r = malloc(sizeof(struct StatementList));
	r->head = head;
	r->tail = tail;
	return r;
}

void freeStatementList(struct StatementList* f)
{
	if(f == NULL) return;
	freeStatement(f->head);
	freeStatementList(f->tail);
	free(f);
}

#endif
